﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Web;

namespace SMSService
{
    public static class SMEntry
    {
        /// <summary>
        /// 初始化接口函数
        /// </summary>
        /// <param name="DBName">数据库服务器</param>
        /// <param name="Account">数据库用户名</param>
        /// <param name="Password">数据库用户密码</param>
        /// <returns></returns>
        [DllImport("SMEntry.dll")]
        public static extern int SP_Startup(string DBName, string Account, string Password);

        /// <summary>
        /// 登录清空函数
        /// </summary>
        [DllImport("SMEntry.dll")]
        public static extern void SP_Cleanup();

        /// <summary>
        /// API调用登录函数
        /// </summary>
        /// <param name="Operator"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        [DllImport("SMEntry.dll")]
        public static extern int SP_Login(string Operator, string Password);


        /// <summary>
        /// 登出函数
        /// </summary>
        [DllImport("SMEntry.dll")]
        public static extern void SP_Logout();

        /// <summary>
        /// 发送短信的函数功能
        /// </summary>
        /// <param name="AtTime">发送时间</param>
        /// <param name="SourceAddr">源地址</param>
        /// <param name="DestAddr">接受地址</param>
        /// <param name="Content">发送的短信内容</param>
        /// <param name="ContentLen">短信内容长度</param>
        /// <param name="NeedStateReport">是否需要状态报告</param>
        /// <param name="ServiceID">服务ID</param>
        /// <param name="FeeType">费用类型</param>
        /// <param name="FeeCode">收费标准</param>
        /// <returns></returns>
        [DllImport("SMEntry.dll")]
        public static extern int SubmitShortMessage(string AtTime, string SourceAddr, string DestAddr,
            string Content, uint ContentLen, byte NeedStateReport, string ServiceID, string FeeType, string FeeCode);


        /// <summary>
        /// 接受短信功能函数
        /// </summary>
        /// <param name="DestAddrMask">接收短信目标地址掩码</param>
        /// <param name="SourceAddr">接收短信的源地址</param>
        /// <param name="DestAddr">接收短信的目的地址</param>
        /// <param name="Content">接收短信内容</param>
        /// <param name="ContentLen">分配给Content的字节长度</param>
        /// <param name="RecvTime">接收到短信的时间</param>
        /// <returns></returns>
        [DllImport("SMEntry.dll")]
        public static extern int GetShortMessage(
                string DestAddrMask,
                [MarshalAs(UnmanagedType.LPStr)] StringBuilder SourceAddr,
                [MarshalAs(UnmanagedType.LPStr)] StringBuilder DestAddr,
                [MarshalAs(UnmanagedType.LPStr)] StringBuilder Content,
                ref uint ContentLen,
                [MarshalAs(UnmanagedType.LPStr)] StringBuilder RecvTime);
    }
}